﻿@model IEnumerable<QuanLyGiaoVuUI.Models.GiangVien.GiangVienViewModel>

@{
    Layout = null;
}

<style>
    .table-holder {
        height: 400px;
        overflow-y: scroll;
    }
</style>

    <input type="hidden" value="" id="SelectedGiangVienId" />
    <input type="hidden" value="" id="thongtinGiangVien" />
<div class="table-holder">
    <table class="data display datatable" id="GiangVienTable">
        <tr>
            <th>
            </th>
            <th>
                @Html.DisplayNameFor(m => m.MaGiangVien)
            </th>
            <th>
                @Html.DisplayNameFor(m => m.HoTenGV)
            </th>
            <th>
                @Html.DisplayNameFor(m => m.GioiTinh)
            </th>
            <th>
                @Html.DisplayNameFor(m => m.NgaySinh)
            </th>
            <th>
                @Html.DisplayNameFor(m => m.Email)
            </th>
        </tr>
    
        @{int count = 0;}
    @foreach (var item in Model) {
        <tr class="gradeA @(++count % 2 == 0 ? "even" : "odd")">
            <td class="gradeA @(++count % 2 == 0 ? "even" : "odd")">
                <input type="checkbox" name="giangVienIds" value="@item.ID" class="giangVienId" />
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.MaGiangVien)
            </td>
            <td class="hoTenGV">
                @Html.DisplayFor(modelItem => item.HoTenGV)
            </td>
            <td>
                @(item.GioiTinh.Equals("1") ? "Nam" : "Nữ")
            </td>
            <td>
                <span>@(item.NgaySinh.HasValue ? ((DateTime)item.NgaySinh).ToShortDateString() : String.Empty)</span>
            </td>
            <td class="email">
                <span>@item.Email</span>
            </td>
        </tr>
    }
    </table>
    </div>

    <script>
        var ChonNguoiNhanObject = new function () {
            this.LayDanhSachGiangVienId = function(){
                var result = '';
                $(".giangVienId").each(function () {
                    if ($(this).is(":checked")) {
                        result += $(this).val() + ',';
                    }
                });
                if (result.length > 0) {
                    result = result.substr(0, result.length - 1);
                }
                return result;
            }

            this.LayDanhSachThongTinGiangVien = function() {
                var result = '';
                $(".giangVienId").each(function () {
                    if ($(this).is(":checked")) {
                        var localRoot = $(this).parent().parent();
                        var hoTenGV = localRoot.find(".hoTenGV").first().html().trim();
                        var email = localRoot.find(".email").first().find("span").first().html().trim();
                        result += ' ' + hoTenGV + '(' + email + ')' + ',';
                    }
                });
                if (result.length > 0) {
                    result = result.substr(0, result.length - 1);
                }
                return result.trim();
            }
        }

        $(document).ready(function () {
            $("#GiangVienTable").find("tr.gradeA").each(function () {
                $(this).bind("click", function () {
                    var checkBox = $(this).find("input[type=checkbox]").first();
                    if (checkBox) {
                        var checkStatus = checkBox.is(":checked");
                        checkBox.attr("checked", !checkStatus);
                    }
                });
            });

            $("#GiangVienTable input[type=checkbox]").bind("click", function () {
                $(this).attr("checked",!$(this).is(":checked"));
            });
        });
    </script>